//Modal移动方法
$.fn.ModalMove = function() {
	var modal = this;
	var bool = false;
	var beginTop = 0;
	var beginLeft = 0;
	var mouseTop = 0;
	var mouseLeft = 0;
	var endTop = 0;
	var endLeft = 0;
	$(modal).find(".modal-header").mousedown(function(e) {
		//$(modal).css("filter", "alpha(opacity=50)");
		document.onselectstart = new Function('return false');
		$(this).css('cursor', 'move');
		modalOffset = $(modal).offset();
		beginLeft = modalOffset.left;
		beginTop = modalOffset.top;
		mouseLeft = e.pageX;
		mouseTop = e.pageY;
		bool = true;
	});
	$(document).mouseup(function(e) {
		whenMouseUp();
	});
	$(document).mousemove(function(e) {
		if (!bool) {
			return;
		}
		modalOffset = $(modal).offset();
		endLeft = e.pageX - mouseLeft;
		endTop = e.pageY - mouseTop;
		var topOffset = parseInt(endTop * 1 + beginTop * 1);
		var minTop = 0;
		var maxTop = $(document).height()-$(modal).find(".modal-header").height();
		var topLast = topOffset<=minTop?minTop:(topOffset>=maxTop?maxTop:topOffset);
		var leftOffset = parseInt(endLeft * 1 + beginLeft * 1);
		var minLeft = 50-$(modal).width();
		var maxLeft = $(document).width()-50;
		var leftLast = leftOffset<=minLeft?minLeft:(leftOffset>=maxLeft?maxLeft:leftOffset);
		$(modal).offset({
			top :topLast,
			left : leftLast
		});
	});
	$(document).mouseleave(function() {
		whenMouseUp();
	});
	function whenMouseUp() {
		//$(".modal").css("filter", "alpha(opacity=100)");
		$(this).css('cursor', '');
		document.onselectstart = new Function('return true');
		bool = false;
	}
};
